package com.erytech.linktalk.web.client.dataview;

import com.erytech.linktalk.web.client.datasource.RoomDataSource;
import com.erytech.linktalk.web.client.datasource.RoomUpdateEvent;
import com.erytech.linktalk.web.client.framework.DataUpdateEvent;
import com.erytech.linktalk.web.client.framework.DataView;
import com.google.gwt.user.client.ui.HorizontalPanel;

public class RoomView extends DataView {

	HorizontalPanel container = new HorizontalPanel();

	MessagesView messagesView;

	UserListView userListView;

	public RoomView(RoomDataSource roomDataSource) {
		super(roomDataSource);
		this.messagesView = new MessagesView(roomDataSource
				.getMessageDataSource());
		this.userListView = new UserListView(roomDataSource
				.getUserDataSource());

		container.setSpacing(4);
		container.setStyleName("room-panel");
		container.setSize("100%", "100%");
		container.add(messagesView);
		container.add(userListView);

		container.setCellHeight(messagesView, "100%");
		container.setCellHeight(userListView, "100%");
		container.setCellWidth(messagesView, "80%");
		container.setCellWidth(userListView, "20%");

		initWidget(container);
	}

	public void onWindowResized(int windowWidth, int windowHeight) {
		container.setWidth(windowWidth + "px");
		container.setHeight(windowHeight + "px");
		userListView.onWindowResized();
		messagesView.onWindowResized();
	}

	public void onDataUpdateEvent(DataUpdateEvent event) {		
		if (event instanceof RoomUpdateEvent) {
			RoomUpdateEvent roomUpdateEvent = (RoomUpdateEvent) event;
			if (roomUpdateEvent.getType() == RoomUpdateEvent.ENTER_ROOM) {
				userListView.showWaitIcon();
			} else if (roomUpdateEvent.getType() == RoomUpdateEvent.LEFT_ROOM) {
				// nothing to do
			}
		}
	}

}